package com.qs.util;

import java.util.Hashtable;
import java.util.List;

import com.infomanage.dao.BaseDAO;
import com.infomanage.exception.DaoException;
import com.jiuqi.webtree.TreeNode;
import com.jiuqi.webtree.TreeNodeList;
import com.jiuqi.webtree.WebTreeInfo;
import com.jiuqi.webtree.WebTreeIntf;
import com.jiuqi.webtree.util.StringUtils;
import com.qs.dao.QsEquEntryDAO;
import com.qs.po.QsEquClass;
import com.qs.vo.QsEquEntryItem;

public class EquipmentTree implements WebTreeIntf{
	private BaseDAO<QsEquClass> classDAO = new BaseDAO<QsEquClass>();
	private QsEquEntryDAO entryDAO = new QsEquEntryDAO();
	
	@Override
	public boolean delNode(String arg0, boolean arg1, String arg2) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public String getErrorMessage() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String[] getNodePaths(String arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public TreeNodeList getNodes(String parentId, int arg1, WebTreeInfo arg2) {
		TreeNodeList childNodes = new TreeNodeList(1, 1);
		if(StringUtils.isEmpty(parentId)) {
			try {
				List<QsEquClass> equClass = classDAO.findAll(QsEquClass.class);
				if(equClass != null) {
					for (QsEquClass qsEquClass : equClass) {
						TreeNode treeNode = new TreeNode(String.valueOf(qsEquClass.getId()), qsEquClass.getTitle(), true, null, false);
						childNodes.addNode(treeNode);
					}
				}
			} catch (DaoException e) {
				e.printStackTrace();
			}
		}else {
			try {
				List<QsEquEntryItem> entryItems = entryDAO.findByClass(Integer.parseInt(parentId));
				if(entryItems != null) {
					for (QsEquEntryItem qsEquEntryItem : entryItems) {
						TreeNode treeNode = new TreeNode(String.valueOf(qsEquEntryItem.getBean().getId()), qsEquEntryItem.getBean().getTitle(), false, null, false);
						childNodes.addNode(treeNode);
					}
				}
			} catch (DaoException e) {
				e.printStackTrace();
			}
		}
		return childNodes;
	}

	@Override
	public boolean insertNode(String arg0, String arg1, Hashtable arg2) {
		// TODO Auto-generated method stub
		return false;
	}

}
